using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace SimpleFramework
{
    public class StateMachine<T> : ITimer
    {
        protected Dictionary<T, StateBase> m_StateDict = new Dictionary<T, StateBase>();
        protected T m_CurId;
        protected StateBase m_CurState = new StateBase();

        public StateMachine()
        {
            TimerSystem.Instance.Add(this);
        }

        public virtual void Add(T key, StateBase state)
        {
            m_StateDict.Add(key, state);
        }

        public virtual void ClearState()
        {
            m_StateDict.Clear();
        }

        public virtual void Change(T id)
        {
            //if (m_CurId.Equals(id))
            //    return;
            m_CurId = id;
            m_CurState.OnExit();
            m_CurState = m_StateDict[id];
            m_CurState.OnEnter();
        }

        public virtual bool Update()
        {
            m_CurState.OnUpdate();
            return false;
        }
    }

}